package create.singleton;

/**
 * @author dali
 * @date 2021-07-06 11:30
 * @Description 懒汉2，线程安全（同步代码块）
 */

public class LanHan2 {
    //防外部new
    private LanHan2() {}
    //静态定义
    private static LanHan2 instance;
    //返回对象时获取
    public static synchronized LanHan2 getInstance() {
        //如果为空则创建
        if (instance == null) {
            instance = new LanHan2();
        }
        return instance;
    }
}
